package cn.yangliu.springbatch.config;

import cn.yangliu.springbatch.job.JobListener;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * the type of springbatch
 *
 * <p>
 * .
 *
 * @author 杨柳
 * @date 2021-07-12
 */
@Configuration
@EnableBatchProcessing
public class SyncBatchConfig {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private JobListener jobListener;

    @Bean
    public Job job(Step handleUserStep, Step handleRoleStep) {
       return jobBuilderFactory.get("user-job-sync")
               .incrementer(new RunIdIncrementer())
               .start(handleUserStep)
               .next(handleRoleStep)
               .listener(jobListener)
               .build();
    }


}
